public class Bullet implements Runnable{
    public boolean isLife() {
        return life;
    }

    public void setLife(boolean life) {
        this.life = life;
    }

    boolean life = true;
    Bullet(int x,int y,int dir) {
        this.x = x;
        this.y = y;
        this.dir = dir;
    }
    private int x;
    private int y;
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }
    public int getSpeed() {
        return speed;
    }
    public void setSpeed(int speed) {
        this.speed = speed;
    }
    public int getDirection() {
        return dir;
    }
    public void setDirection(int dir) {
        this.dir = dir;
    }
    private int speed = 10;
    private int dir;

    @Override
    public void run() {
        while(true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //0向下 1向上 2向左 3向右
            switch(this.getDirection()) {
                case 0:
                    this.setY(this.getY() + this.getSpeed());
                    break;
                case 1:
                    this.setY(this.getY() - this.getSpeed());
                    break;
                case 2:
                    this.setX(this.getX() - this.getSpeed());
                    break;
                case 3:
                    this.setX(this.getX() + this.getSpeed());
                    break;
            }
        }
    }
}